
#include "stdio.h"
#include "windows.h"
typedef struct _SRCFILE
{
    WIN32_FIND_DATA fd;
    bool bIsNew;
}SRCFILE;

void onFindFilesInDir(char* rootDir,  SRCFILE srcFiles[])
{
    //srcFiles = (char *)malloc(FILEEMAX * sizeof(char));
    WIN32_FIND_DATA fd;
    ZeroMemory(&fd, sizeof(WIN32_FIND_DATA));
    HANDLE hFile;
    char tmpPath[256];
    char subPath[256];
    ZeroMemory(tmpPath, 256);
   ZeroMemory(subPath, 256);
    BOOL bRet = TRUE;
    static int nFileSize = 0 ;
    //define the format of the basepath
    strcpy(tmpPath, rootDir);
    if(tmpPath[strlen(tmpPath) -1] != '\\')
    {
        strcat(tmpPath, "\\");
    }
    strcat(tmpPath, "*");
    hFile = FindFirstFile(tmpPath, &fd);
    while (hFile != INVALID_HANDLE_VALUE && bRet)
    {
        if (fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY &&
            strcmp(fd.cFileName, ".") && strcmp(fd.cFileName, ".."))
        {
            strcpy(subPath, rootDir);
            if(subPath[strlen(subPath) -1] != '\\')
            {
                strcat(subPath, "\\");
            }
            strcat(subPath, fd.cFileName);
            onFindFilesInDir(subPath, srcFiles);
        }
        else if(!strcmp(fd.cFileName, ".") || !strcmp(fd.cFileName, ".."))
        {

        }
        else
        {
            srcFiles[nFileSize].fd = fd;
            srcFiles[nFileSize].bIsNew = FALSE;
            nFileSize++;
        }
        bRet = FindNextFile(hFile, &fd);
    }
    srcFiles[nFileSize].bIsNew = TRUE;
    FindClose(hFile);
}

int main()

{
	char* srcDir = "C:\\Users\\Administrator\\Desktop\\sim-3";
    const int FILEEMAX = 1024;
    SRCFILE srcFilesStr[FILEEMAX];
    int sum = 0;
    onFindFilesInDir(srcDir, srcFilesStr);
    while(srcFilesStr[sum].bIsNew == FALSE)
    {
        printf("%s\r\n",srcFilesStr[sum].fd.cFileName);
        sum++;
    }
        printf("the number of the files contained in this directory is %d",sum);
    getchar();
    return 0;
}
